<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    flex.md |  Small Bridge
  </title>
  <meta name="generator" content="hexo-theme-yilia-plus">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/css/main.css">

  
  <script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>
  
  

  

<link rel="alternate" href="/atom.xml" title="Small Bridge" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    <main class="content">
      <section class="outer">
  <article id="post-flex-md" class="article article-type-post" itemscope
  itemprop="blogPost" data-scroll-reveal>

  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  flex.md
</h1>
  

    </header>
    

    
    <div class="article-meta">
      <a href="/2020/05/14/flex-md/" class="article-date">
  <time datetime="2020-05-14T13:27:22.000Z" itemprop="datePublished">2020-05-14</time>
</a>
      
  <div class="article-category">
    <a class="article-category-link" href="/categories/CSS/">CSS</a>
  </div>

      
      
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">4.6k字</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">22分钟</span>
        </span>
    </span>
</div>

      
    </div>
    

    
    
    <div class="tocbot"></div>





    

    
    <div class="article-entry" itemprop="articleBody">
      


      

      
      <p>@<a href="flex布局">TOC</a></p>
<h1 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h1><a id="more"></a>
<p>CSS flex 弹性盒子是一种用在页面上布置元素的布局模式，它是响应式的，分为新老两个版本，老的叫做box，新的叫做flex，我将从新老两个版本进行flex的介绍：</p>
<p>在开始之前，我们必须先知道几个概念，什么是容器？什么是项目？什么是主轴和侧轴？<br>容器：就是用于外层包括的元素，就是设置display:flex的元素<br>项目：容器里面的就是一个一个的项目<br>主轴：默认水平方向，项目永远排列在主轴的正方向上(从左往右),可以自行设置<br>侧轴：主轴确定之后，垂直于主轴就是侧轴，同样可以设置</p>
<p>我们都知道新版本的flex要比老版本的flex强大得多，有没有必要学习老版本的flex?<br>我觉得移动端开发者必须要关注老版本的flex，因为很多移动端设备内核只支持老版本的flex</p>
<h1 id="容器"><a href="#容器" class="headerlink" title="容器"></a>容器</h1><ol>
<li>容器的布局方向<br>容器的布局方向控制的是主轴是哪一根<br>box中我们使用属性  -webkit-box-orient,它有两个值，分别是horizontal水平方向和vertical垂直方向<br>flex中我们使用属性 flex-direction,它也有两个值，分别是row行和column列<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: -webkit-box;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 */</span></span><br><span class="line"><span class="string">				-webkit-box-orient: vertical;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 */</span></span><br><span class="line"><span class="string">				flex-direction: column;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure></li>
<li>容器的排列方向<br>容器的排列方向控制的就是主轴的方向<br>在box中我们使用-webkit-box-direction<br>normal 从左往右(正方向)<br>reverse 从右往左(反方向)<br>在flex中我们还是使用flex-direction,也就是在flex中flex-direction控制主轴的位置和方向<br>row    从左往右的X轴<br>row-reverse 从右往左的X轴<br>column      从上到下的Y轴<br>colume-reverse 从下到上的Y轴<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: -webkit-box;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 */</span></span><br><span class="line"><span class="string">				-webkit-box-orient: horizontal;</span></span><br><span class="line"><span class="string">				/* 控制主轴方向 */</span></span><br><span class="line"><span class="string">				-webkit-box-direction: reverse;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 以及主轴的方向*/</span></span><br><span class="line"><span class="string">				flex-direction: row-reverse;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure></li>
<li>富裕空间管理<br>我们先得知道什么是富裕空间，专业的介绍我就不说了，就是项目之外容器中剩下的空间<br><img src="https://img-blog.csdnimg.cn/20200503201228277.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ0NjI1MTQy,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br>我涂的全是富裕空间<br>这些富裕空间的管理分为两种：<br>a. 主轴上的富裕空间管理</li>
</ol>
<p>box中使用-webkit-box-pack<br>主轴是X轴<br>start   在右边<br>end     在左边<br>center  在两边<br>justify 在项目之间<br>主轴是Y轴<br>start   在下边<br>end     在上边<br>center  在两边<br>justify 在项目之间</p>
<p>flex中使用justify-content<br>flex-start    在主轴的正方向<br>flex-end      在主轴的反方向<br>center        在两边<br>space-between 在项目之间<br>space-around  在项目两边 </p>
<p>b. 侧轴上的富裕空间管理</p>
<p>box中使用-webkit-box-align<br>侧轴是X轴<br>start   在右边<br>end     在左边<br>center  在两边<br>侧轴是Y轴<br>start   在下边<br>end     在上边<br>center  在两边</p>
<p>flex中使用align-items<br>flex-start   在侧轴的正方向<br>flex-end     在侧轴的反方向<br>center       在两边<br>baseline     按基线对齐<br>stretch      等高布局(没有高度才有用)</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: -webkit-box;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 */</span></span><br><span class="line"><span class="string">				-webkit-box-orient: horizontal;</span></span><br><span class="line"><span class="string">				/* 控制主轴方向 */</span></span><br><span class="line"><span class="string">				-webkit-box-direction: normal;</span></span><br><span class="line"><span class="string">				/* 富裕空间管理 */</span></span><br><span class="line"><span class="string">				/* </span></span><br><span class="line"><span class="string">				 start   富裕空间在右边</span></span><br><span class="line"><span class="string">				 end     富裕空间在左边</span></span><br><span class="line"><span class="string">				 center  富裕空间在两边</span></span><br><span class="line"><span class="string">				 justify 富裕空间在项目之间</span></span><br><span class="line"><span class="string">				 */</span></span><br><span class="line"><span class="string">				-webkit-box-pack: justify;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 以及主轴的方向*/</span></span><br><span class="line"><span class="string">				flex-direction: row-reverse;</span></span><br><span class="line"><span class="string">				/* 富裕空间管理 */</span></span><br><span class="line"><span class="string">				/* </span></span><br><span class="line"><span class="string">				 flex-start 富裕空间在主轴的正方向上</span></span><br><span class="line"><span class="string">				 flex-end   富裕空间在主轴的反方向上</span></span><br><span class="line"><span class="string">				 center     富裕空间在两边</span></span><br><span class="line"><span class="string">				 space-between 富裕空间在项目之间</span></span><br><span class="line"><span class="string">				 space-around(box没有的) 富裕空间在项目两边</span></span><br><span class="line"><span class="string">				 */</span></span><br><span class="line"><span class="string">				justify-content: space-around;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<h1 id="项目"><a href="#项目" class="headerlink" title="项目"></a>项目</h1><p>项目中我们需要知道的是弹性空间管理，我们上面提到的富裕空间管理，只决定富裕空间的位置，不会给项目去分配空间，而弹性不一样，弹性就是把富裕的空间按照一定规则分配到各个项目上<br>我们需要提到一个项目上的属性名称叫做弹性因子，你可以理解为占的比例，富裕空间平分成所有项目的弹性因子的总和份，然后在按照各个项目的弹性因子大小分配给其相应的大小</p>
<p>这里给出计算的过程，大家可以自行以下面的例子来验证:<br>可用空间 = (容器大小 - 所有相邻项目的flex-basis总和)<br>可扩展空间 = (可用空间/所有相邻项目flex-grow的总和)<br>每项伸缩大小 = (伸缩基准值 + (可扩展空间*flex-grow值))</p>
<p>flex-basis叫做伸缩基准值，不设置的话就是width或者height，默认值是auto</p>
<p>在box中，我们使用-webkit-box-flex来规定弹性因子的大小<br>flex中使用felx-grow</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: -webkit-box;</span></span><br><span class="line"><span class="string">				/* 控制主轴是哪一根 */</span></span><br><span class="line"><span class="string">				-webkit-box-orient: horizontal;</span></span><br><span class="line"><span class="string">				/* 控制主轴方向 */</span></span><br><span class="line"><span class="string">				-webkit-box-direction: normal;</span></span><br><span class="line"><span class="string">				/* 富裕空间管理(主轴) */</span></span><br><span class="line"><span class="string">				/* </span></span><br><span class="line"><span class="string">				 start   富裕空间在右边</span></span><br><span class="line"><span class="string">				 end     富裕空间在左边</span></span><br><span class="line"><span class="string">				 center  富裕空间在两边</span></span><br><span class="line"><span class="string">				 justify 富裕空间在项目之间</span></span><br><span class="line"><span class="string">				 */</span></span><br><span class="line"><span class="string">				-webkit-box-pack: start;</span></span><br><span class="line"><span class="string">				</span></span><br><span class="line"><span class="string">				 /* 富裕空间管理(侧轴) */</span></span><br><span class="line"><span class="string">				 /* </span></span><br><span class="line"><span class="string">				  start   </span></span><br><span class="line"><span class="string">				  end     </span></span><br><span class="line"><span class="string">				  center  </span></span><br><span class="line"><span class="string">				  */</span></span><br><span class="line"><span class="string">				-webkit-box-align: start;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">				/* 弹性空间管理 */</span></span><br><span class="line"><span class="string">				/* 定义：将主轴上的富裕空间按比例分配到width上 */</span></span><br><span class="line"><span class="string">				/* 指定弹性因子 每一个都为1，一个五个为5，富裕空间50px，故每个width增加10px，变成60px */</span></span><br><span class="line"><span class="string">				-webkit-box-flex: 1;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(1)&#123;</span></span><br><span class="line"><span class="string">				/* 第一个宽80px，其他的55px */</span></span><br><span class="line"><span class="string">				-webkit-box-flex: 6;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				flex-direction: row-reverse;</span></span><br><span class="line"><span class="string">				justify-content: space-around;</span></span><br><span class="line"><span class="string">				align-items: flex-start;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">				/* 弹性空间管理 */</span></span><br><span class="line"><span class="string">				flex-grow: 1;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<h1 id="新版本新增"><a href="#新版本新增" class="headerlink" title="新版本新增"></a>新版本新增</h1><p>相比于老版本box，新版flex新增了很多属性，我们一一介绍</p>
<ol>
<li>容器新增</li>
</ol>
<p>flex-wrap:控制的是侧轴的方向<br>nowrap  不换行<br>wrap    侧轴方向由上而下        (flex-shrink失效)<br>wrap-reverse 侧轴方向由下而上      (flex-shrink失效)</p>
<p>align-content:多行/列时，侧轴上富裕空间的管理(将多行/列看成一个整体)</p>
<p>flex-flow：flex-direction和flex-wrap的简写属性<br>本质上控制了主轴及侧轴的位置和方向</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 100px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				/* flex-direction: row; */</span></span><br><span class="line"><span class="string">				justify-content: flex-start;</span></span><br><span class="line"><span class="string">				/* 单行单列时侧轴上的富裕空间管理 */</span></span><br><span class="line"><span class="string">				align-items: flex-start;</span></span><br><span class="line"><span class="string">				/* 控制侧轴的方向,新行/列将沿侧轴方向堆砌 */</span></span><br><span class="line"><span class="string">				/* flex-wrap: wrap; */</span></span><br><span class="line"><span class="string">				/* 多行多列时的富裕空间管理 会把多行多列看成一个整体 */</span></span><br><span class="line"><span class="string">				align-content: flex-start;</span></span><br><span class="line"><span class="string">				/* flex-direction和flex-wrap的简写，控制主轴及侧轴的方向和位置 */</span></span><br><span class="line"><span class="string">				flex-flow: row wrap; </span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>

<ol start="2">
<li>项目新增</li>
</ol>
<p>order：控制项目的排列顺序<br>align-self：项目自身富裕空间的管理<br>flex-shrink:收缩因子(默认值为1)<br>当一行宽度不够时，项目将会收缩<br>这里给出收缩时的计算规则:<br>–计算收缩因子与基准值乘的总和<br>var a = 每一项flex-shrink<em>flex-basis之和<br>–计算收缩因数<br>收缩因数 = (项目的收缩因子</em>项目基准值)/第一步计算总和<br>var b = (flex-shrink*flex-basis)/a<br>–移除空间的计算<br>移除空间 = 项目收缩因数 * -溢出空间<br>var c = b * -溢出空间<br>还是比较复杂的，所以下面例子中我给出了详细的计算<br>注意，这只是其中的一种计算方式，还有一种情况就是每个项目收缩到小于它里面的内容所占的大小了，这就不能再收缩了，这时它会将其收缩到内容大小，多余没收缩的交给其他项目承担，这实质上一个递归的过程，可复杂了，感兴趣的，大家看看API吧，一般我们做项目的时候会注意项目里的内容进行相应的设计</p>
<p>flex-basis:伸缩规则计算的基准值(默认width或者height的值)</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				flex-flow: row nowrap; </span></span><br><span class="line"><span class="string">				justify-content: flex-start;</span></span><br><span class="line"><span class="string">				align-items: flex-start;</span></span><br><span class="line"><span class="string">				align-content: flex-start;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			/* order越大，越往后排 */</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(1)&#123;</span></span><br><span class="line"><span class="string">				order: 3;</span></span><br><span class="line"><span class="string">				/* 管理单个项目自己的富裕空间 */</span></span><br><span class="line"><span class="string">				align-self: flex-end;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(2)&#123;</span></span><br><span class="line"><span class="string">				order: 2;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(3)&#123;</span></span><br><span class="line"><span class="string">				order: 4;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(4)&#123;</span></span><br><span class="line"><span class="string">				order: 5;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(5)&#123;</span></span><br><span class="line"><span class="string">				order: 1;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				flex-flow: row nowrap; </span></span><br><span class="line"><span class="string">				justify-content: flex-start;</span></span><br><span class="line"><span class="string">				align-items: flex-start;</span></span><br><span class="line"><span class="string">				align-content: flex-start;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">				flex-basis: 100;</span></span><br><span class="line"><span class="string">				flex-grow: 1;</span></span><br><span class="line"><span class="string">				/* flex-basis  伸缩基准值 */</span></span><br><span class="line"><span class="string">				/* 扩展因子 flex-grow的算法 </span></span><br><span class="line"><span class="string">				   可用空间 = (容器大小 - 所有相邻项目flex-basis的总和)  没有flex-basis时默认为宽度</span></span><br><span class="line"><span class="string">				   300 - 100*5 = -200</span></span><br><span class="line"><span class="string">				   可扩展空间 = (可用空间 / 所有相邻项目flex-grow的总和)</span></span><br><span class="line"><span class="string">				   -200/5 = -40</span></span><br><span class="line"><span class="string">				   每项伸缩大小 = (伸缩基准值  + (可扩展空间*flex-grow的值))</span></span><br><span class="line"><span class="string">				   100 + (-40)*1 = 60</span></span><br><span class="line"><span class="string">				*/</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(1)&#123;</span></span><br><span class="line"><span class="string">				order: 3;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(2)&#123;</span></span><br><span class="line"><span class="string">				order: 2;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(3)&#123;</span></span><br><span class="line"><span class="string">				order: 4;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(4)&#123;</span></span><br><span class="line"><span class="string">				order: 5;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(5)&#123;</span></span><br><span class="line"><span class="string">				order: 1;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			/* </span></span><br><span class="line"><span class="string">			 *flex容器</span></span><br><span class="line"><span class="string">			 *flex项目</span></span><br><span class="line"><span class="string">			 *主轴</span></span><br><span class="line"><span class="string">			 *侧轴</span></span><br><span class="line"><span class="string">			 *项目永远在主轴的正方向上排列</span></span><br><span class="line"><span class="string">			 */</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 100px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">				flex-flow: row nowrap; </span></span><br><span class="line"><span class="string">				justify-content: flex-start;</span></span><br><span class="line"><span class="string">				align-items: flex-start;</span></span><br><span class="line"><span class="string">				align-content: flex-start;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				width: 50px;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				text-align: center;</span></span><br><span class="line"><span class="string">				line-height: 50px;</span></span><br><span class="line"><span class="string">				flex-shrink: 1;</span></span><br><span class="line"><span class="string">				/* flex-shrink 收缩因子 只有一行时有效 默认值为1 */</span></span><br><span class="line"><span class="string">				/* 收缩的算法</span></span><br><span class="line"><span class="string">				   1. 计算收缩因子与基准值乘的总和</span></span><br><span class="line"><span class="string">						1*20+50*4 = 220</span></span><br><span class="line"><span class="string">				   2. 计算收缩因数</span></span><br><span class="line"><span class="string">						收缩因数 = (项目的收缩因子*项目基准值)/第一步计算总和</span></span><br><span class="line"><span class="string">						1*20/220 = 1/11</span></span><br><span class="line"><span class="string">						1*50/220 = 5/22</span></span><br><span class="line"><span class="string">				   3. 移除空间的计算</span></span><br><span class="line"><span class="string">						移除空间 = 项目收缩因数 * -溢出空间  </span></span><br><span class="line"><span class="string">						1/11*-(20+50*4-100) = -10.几</span></span><br><span class="line"><span class="string">						5/22*-(120) = -27.几</span></span><br><span class="line"><span class="string">						</span></span><br><span class="line"><span class="string">						20 - 10.几 = 9.几</span></span><br><span class="line"><span class="string">						50 - 27.几 = 22.几</span></span><br><span class="line"><span class="string">				 */</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(1)&#123;</span></span><br><span class="line"><span class="string">				order: 3;</span></span><br><span class="line"><span class="string">				width: 20px;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(2)&#123;</span></span><br><span class="line"><span class="string">				order: 2;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(3)&#123;</span></span><br><span class="line"><span class="string">				order: 4;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(4)&#123;</span></span><br><span class="line"><span class="string">				order: 5;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item:nth-child(5)&#123;</span></span><br><span class="line"><span class="string">				order: 1;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				2</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				3</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				5</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<p>看到这里了，我们发现侧轴上的富裕空间管理，有好几个，align-items,align-self,align-content,下面说说他们的区别：<br>align-items     单行单列<br>align-self      自身<br>align-content   多行多列</p>
<p>优先级:align-content &gt; align-self &gt; align-items</p>
<h1 id="flex简写属性"><a href="#flex简写属性" class="headerlink" title="flex简写属性"></a>flex简写属性</h1><p>在介绍简写属性之前，我们看一个flex的应用，等分布局</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">	&lt;head&gt;</span><br><span class="line">		&lt;meta charset=<span class="string">"utf-8"</span>&gt;</span><br><span class="line">		&lt;title&gt;&lt;<span class="regexp">/title&gt;</span></span><br><span class="line"><span class="regexp">		&lt;style type="text/</span>css<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			*&#123;</span></span><br><span class="line"><span class="string">				margin: 0;</span></span><br><span class="line"><span class="string">				padding: 0;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&#123;</span></span><br><span class="line"><span class="string">				width: 300px;</span></span><br><span class="line"><span class="string">				height: 400px;</span></span><br><span class="line"><span class="string">				border: 1px solid;</span></span><br><span class="line"><span class="string">				margin: 100px auto;</span></span><br><span class="line"><span class="string">				display: flex;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">			#wrap&gt;.item&#123;</span></span><br><span class="line"><span class="string">				height: 50px;</span></span><br><span class="line"><span class="string">				background: pink;</span></span><br><span class="line"><span class="string">				/* 等分布局 */</span></span><br><span class="line"><span class="string">				/* 宽度靠内容撑开，基准值设为0 ，因子设为1，相当于平分成5份 */</span></span><br><span class="line"><span class="string">				flex-grow: 1;</span></span><br><span class="line"><span class="string">				flex-basis: 0;</span></span><br><span class="line"><span class="string">				flex-shrink: 1;</span></span><br><span class="line"><span class="string">			&#125;</span></span><br><span class="line"><span class="string">		&lt;/style&gt;</span></span><br><span class="line"><span class="string">	&lt;/head&gt;</span></span><br><span class="line"><span class="string">	&lt;body&gt;</span></span><br><span class="line"><span class="string">		&lt;div id="</span>wrap<span class="string">"&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				1</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				22</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				333</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				4444</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">			&lt;div class="</span>item<span class="string">"&gt;</span></span><br><span class="line"><span class="string">				55555</span></span><br><span class="line"><span class="string">			&lt;/div&gt;</span></span><br><span class="line"><span class="string">		&lt;/div&gt;</span></span><br><span class="line"><span class="string">	&lt;/body&gt;</span></span><br><span class="line"><span class="string">&lt;/html&gt;</span></span><br></pre></td></tr></table></figure>
<p>至于为什么是等分，大家按照上面的计算规则算一下就知道了<br>简写属性就是等分布局的简写，上面的三行可以简写成<br>       flex: 1<br>       表示 flex-grow: 1; flex-shrink: 1; flex-basis: 0%;<br>       这就是一个等分布局</p>
<p>好了，我的分享就到这里了，谢谢大家</p>

      
      <!-- reward -->
      
      <div id="reward-btn">
        打赏
      </div>
      
    </div>
    
    
      <!-- copyright -->
      
        <div class="declare">
          <ul class="post-copyright">
            <li>
              <i class="ri-copyright-line"></i>
              <strong>版权声明： </strong s>
              本博客所有文章除特别声明外，均采用 <a href="https://www.apache.org/licenses/LICENSE-2.0.html" rel="external nofollow"
                target="_blank">Apache License 2.0</a> 许可协议。转载请注明出处！
            </li>
          </ul>
        </div>
        
    <footer class="article-footer">
      
          
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=https://lockme.gitee.io/2020/05/14/flex-md/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>
      
      
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/CSS3/" rel="tag">CSS3</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/%E5%BC%B9%E6%80%A7%E5%B8%83%E5%B1%80/" rel="tag">弹性布局</a></li></ul>


    </footer>

  </div>

  
  
  <nav class="article-nav">
    
      <a href="/2020/05/14/CSS-media-md/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            CSS-media.md
          
        </div>
      </a>
    
    
      <a href="/2020/05/14/CSS3-3D-animation-md/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">CSS3-3D&amp;animation.md</div>
      </a>
    
  </nav>


  

  
  
<!-- valine评论 -->
<div id="vcomments-box">
    <div id="vcomments">
    </div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js'></script>
<script>
    new Valine({
        el: '#vcomments',
        app_id: 'pmaQYnbUE9O0H1hiYKLiec4R-gzGzoHsz',
        app_key: 'LMujtI79W4vgEQ3Az5IMo50y',
        path: window.location.pathname,
        notify: 'false',
        verify: 'false',
        avatar: 'mp',
        placeholder: '给我的文章加点评论吧~',
        recordIP: true
    });
    const infoEle = document.querySelector('#vcomments .info');
    if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
        infoEle.childNodes.forEach(function (item) {
            item.parentNode.removeChild(item);
        });
    }
</script>
<style>
    #vcomments-box {
        padding: 5px 30px;
    }

    @media screen and (max-width: 800px) {
        #vcomments-box {
            padding: 5px 0px;
        }
    }

    #vcomments-box #vcomments {
        background-color: #fff;
    }

    .v .vlist .vcard .vh {
        padding-right: 20px;
    }

    .v .vlist .vcard {
        padding-left: 10px;
    }
</style>

  

  
  
  

</article>
</section>
      <footer class="footer">
  <div class="outer">
    <ul class="list-inline">
      <li>
        &copy;
        2020
        月下ctrlc
      </li>
      <li>
        
        Powered by
        
        
        <a href="https://hexo.io" target="_blank">Hexo</a> Theme <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul class="list-inline">
      <li>
        
        
        <span>
  <i>PV:<span id="busuanzi_value_page_pv"></span></i>
  <i>UV:<span id="busuanzi_value_site_uv"></span></i>
</span>
        
      </li>
      
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="to_top">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>
      </div>
    </main>
    <aside class="sidebar">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/avatar.jpg" alt="Small Bridge"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags/Vue/">Vue</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="http://shenyu-vip.lofter.com" target="_blank" rel="noopener">主题作者相册</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2020/03/18/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>拿钱砸死我吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.png">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wechat.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/share.js"></script>


<script src="/js/lazyload.min.js"></script>


<script>
  try {
    var typed = new Typed("#subtitle", {
      strings: ['面朝大海，春暖花开', '愿你一生努力，一生被爱', '想要的都拥有，得不到的都释怀'],
      startDelay: 0,
      typeSpeed: 200,
      loop: true,
      backSpeed: 100,
      showCursor: true
    });
  } catch (err) {
  }

</script>




<script src="/js/tocbot.min.js"></script>

<script>
  // Tocbot_v4.7.0  http://tscanlin.github.io/tocbot/
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto',
    onClick: (e) => {
      $('.toc-link').removeClass('is-active-link');
      $(`a[href=${e.target.hash}]`).addClass('is-active-link');
      $(e.target.hash).scrollIntoView();
      return false;
    }
  });
</script>



<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/js/ayer.js"></script>



<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>


<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
      tex2jax: {
          inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
          processEscapes: true,
          skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
  });

  MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for(i=0; i < all.length; i += 1) {
          all[i].SourceElement().parentNode.className += ' has-jax';
      }
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.6/unpacked/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
  var ayerConfig = {
    mathjax: true
  }
</script>



<script src="/js/busuanzi-2.3.pure.min.js"></script>



<script type="text/javascript" src="https://js.users.51.la/20544303.js"></script>


    
  </div>
</body>

</html>